package team.seekers.hula.message.message.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.auth.service.MindUtils;
import team.seekers.hula.message.message.entity.dto.*;
import team.seekers.hula.message.message.entity.vo.MessageListVO;
import team.seekers.hula.message.message.entity.vo.MessageReplyListVO;
import team.seekers.hula.message.message.service.MessageService;

/**
 * <p>
 * 消息管理控制器
 * </p>
 *
 * @author hbc
 * @since 2021-02-23
 */
@Controller
@ApiResponseBody
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @PostMapping("/add")
    public void add(@RequestBody MessageAddDTO addVO){
        messageService.add(addVO);
    }

    /**
     *
     * 发消息
     */
    @PostMapping("/send")
    public void send(@RequestBody MessageSendDTO messageSendDTO) {
        messageSendDTO.setUserId(MindUtils.getUserId());
        messageService.send(messageSendDTO);
    }

    /**
     *
     *
     * 回复消息
     */
    @PostMapping("/reply")
    public void reply(@RequestBody MessageReplyDTO messageReplyDTO) {
        messageReplyDTO.setUserId(MindUtils.getUserId());
        messageService.reply(messageReplyDTO);
    }


    /**
     *
     *
     * 开始私信
     */
    @PostMapping("/letter")
    public String letter(@RequestBody MessageLetterDTO messageLetterDTO) {
        messageLetterDTO.setUserId(MindUtils.getUserId());
        return messageService.letter(messageLetterDTO);
    }

    /**
     *
     *显示私信
     *
     */
    @GetMapping("/display")
    public PageResult<MessageReplyListVO> display(MessageDisplayDTO messageDisplayDTO) {
        messageDisplayDTO.setFromId(MindUtils.getUserId());
        return messageService.display(messageDisplayDTO);
    }

    @GetMapping("/hasRead")
    public void hasRead(@RequestParam("messageId") String messageId) {messageService.hasRead(messageId);
    }

    @GetMapping("/hasReadAll")
    public void hasReadAll(){
        messageService.hasReadAll();
    }


    /**
     *
     * 轮询接收消息
     */
    @GetMapping("/pageOrderByTime")
    public PageResult<MessageReplyListVO> pageOrderByTime(MessageQueryDTO messageQueryDTO){
        PageResult<MessageReplyListVO> messageListVOPageResult = messageService.pageOrderByTime(messageQueryDTO.getPageNow(), messageQueryDTO.getPageSize(), messageQueryDTO);
        return messageListVOPageResult;
    }

    @GetMapping("/getNotReadNumber")
    public Integer getNotReadNumber(){
        return messageService.getNotReadNumber();
    }

    /**
     *
     * 同意交流
     */
    @PostMapping("/agree")
    public void agree(@RequestBody AgreeDTO agreeDTO) {
        agreeDTO.setUserId(MindUtils.getUserId());
        messageService.agree(agreeDTO);
    }

    /**
     *
     * 管理后台删除聊天（隧道）
     */
    @PostMapping("/delete")
    public void deleteMessage(@RequestBody MessageDeleteDTO messageDeleteDTO) {
        messageService.deleteMessage(messageDeleteDTO);
    }

    /**
     *
     * 显示私信列表
     */
    @GetMapping("/listUser")
    public PageResult<MessageListVO> listUser(MessageListDTO messageListDTO) {
        messageListDTO.setFromId(MindUtils.getUserId());
        return messageService.listUser(messageListDTO);
    }

}

